import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { viteMockServe } from "vite-plugin-mock";
import { resolve } from "path"; // 编辑器提示 path 模块找不到，可以yarn add @types/node --dev
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
export default defineConfig({
  plugins: [
    vue(),
    viteMockServe({ supportTs: true }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@/": resolve(__dirname, "src/"), // 设置 `@` 指向 `src` 目录
    },
  },
  server: {
    port: 3000, // 设置服务启动端口号
    open: true, // 设置服务启动时是否自动打开浏览器
    // 代理
    proxy: {
      "/api": {
        target: "http://API网关所在域名",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
      "/wxyyapi": {
        target: "http://localhost:3043",
        changeOrigin: true,
        prependPath: true,
        rewrite: (path) => path.replace("/wxyyapi", ""),
      },
    },
  },
});
